import { Controller } from "../../mvc/core/Controller";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { RolePlayer } from "../scene/player/entity/RolePlayer";
import { PlayerEvent } from "../scene/events/PlayerEvent";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { ServerCommand } from "../mvc/ServerCommand";
import { EGateCommand } from "../../../Message/Command/EGateCommand";
import { DataEvent } from "../events/DataEvent";
import { FriendBlessReceivePanel } from "../view/friendsBless/FriendBlessReceivePanel";
import { FriendBlessExpBottleButton } from "../view/friendsBless/FriendBlessExpBottleButton";
import { LayerManager } from "../manager/LayerManager";
import { TweenMax } from "../../../com/greensock/TweenMax";
import { BlessExpBottleDescPanel } from "../view/friendsBless/BlessExpBottleDescPanel";
import { PopupManager } from "../manager/PopupManager";
import { EffectManager } from "../manager/EffectManager";
import { GuideTipsManager } from "../manager/GuideTipsManager";
import { GameProxy } from "../mvc/GameProxy";
import { FriendBlessSendPanel } from "../view/friendsBless/FriendBlessSendPanel";
import { SFriendBlessSucess } from "../../../Message/Public/SFriendBlessSucess";
import { BlessHintIconFu } from "../view/friendsBless/BlessHintIconFu";
import { UiHintIconView } from "../view/uiIconBtn/UiHintIconView";
import { BlessHintIcon } from "../view/friendsBless/BlessHintIcon";
import { SFriendBlessInfo } from "../../../Message/Public/SFriendBlessInfo";
import { ClockManager } from "../manager/ClockManager";
import { EBlessMsgType } from "../../../Message/Public/EBlessMsgType";
import { MsgManager } from "../manager/MsgManager";
import { Language } from "../../../extend/language/Language";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SFriendBlessExpBottle } from "../../../Message/Public/SFriendBlessExpBottle";
import { ExpAddEffect } from "../view/effect/ExpAddEffect";
import { ExpAddEffectInfo } from "../resource/info/ExpAddEffectInfo";
import { SPublicMiniPlayer } from "../../../Message/Public/SPublicMiniPlayer";
import { OneKeyFriendsWin } from "../view/friendsBless/onekeyFriends/OneKeyFriendsWin";
//class FriendsBlessController
    
    export  class FriendsBlessController extends Controller
    {
        constructor()
        {
            
            super();this._blessHintIconFuDic = new Map<any, any> /* flash.utils.Dictionary */();
            return;
        }

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.FriendBless_ShowBlessesList, this.onShowBlessesList);
            Dispatcher.addEventListener(EventName.FriendBless_ExpBottleButtonClick, this.onExpBottleButtonClick);
            Dispatcher.addEventListener(EventName.FriendBless_ExpBottleGetExp, this.onGetBottleExp);
            Dispatcher.addEventListener(EventName.FriendBless_GetBottleExpSuccess, this.onGetBottleExpSuccess);
            Dispatcher.addEventListener(EventName.FriendBless_ShowSendBlessList, this.onShowSendBlessPanel);
            Dispatcher.addEventListener(EventName.friendbless_SendBless, this.doSendBless);
            Dispatcher.addEventListener(EventName.OneKeyFriends_ShowWin, this.onGetOnekeyFriendsInfo);
            Dispatcher.addEventListener(EventName.OneKeyFriends_MakeFriend, this.onOneKeyMakeFriends);
            Dispatcher.addEventListener(EventName.OneKeyFriends_TimeChange, this.onOneKeyFriendsUseTimeChange);
            RolePlayer.instance.addEventListener(PlayerEvent.RoleLevelUpdate, this.onRoleLevelUpdate);
            NetDispatcher.addCmdListener(ServerCommand.FriendBlessSuccess, this.onFriendBlessSuccess);
            NetDispatcher.addCmdListener(ServerCommand.FriendBlessTips, this.onFriendBlessTipsCommand);
            NetDispatcher.addCmdListener(ServerCommand.FriendBlessList, this.onFriendBlessTipsCommand);
            NetDispatcher.addCmdListener(ServerCommand.FriendBlessNumChange, this.onFriendBlessNumChange);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateFriendBlessExpBottle, this.onFriendBlessExpBoottleCommand);
            return;
        }

        /* internal  */onShowBlessesList(arg1: DataEvent): void
        {
            if (!this._blessReceivePanel) 
            {
                this._blessReceivePanel = new FriendBlessReceivePanel();
            }
            this._blessReceivePanel.showBlessReceive(arg1.data as Array<any>);
            return;
        }

        public showFbExpBottleButton(): void
        {
            if (!this._FbExpBottleBtn) 
            {
                this._FbExpBottleBtn = new FriendBlessExpBottleButton();
                this._FbExpBottleBtn.x = 500;
                this._FbExpBottleBtn.y = 160;
                LayerManager.uiLayer.addChild(this._FbExpBottleBtn);
                TweenMax.to(this._FbExpBottleBtn, 1, {"x": 150, "y": 160});
            }
            return;
        }

        public hideFbExpBottleButton(): void
        {
            if (this._FbExpBottleBtn && this._FbExpBottleBtn.parent) 
            {
                this._FbExpBottleBtn.parent.removeChild(this._FbExpBottleBtn);
                this._FbExpBottleBtn = null;
            }
            return;
        }

        /* internal  */onExpBottleButtonClick(arg1: DataEvent): void
        {
            if (!this._blessBottleDescPanel) 
            {
                this._blessBottleDescPanel = new BlessExpBottleDescPanel();
            }
            this._blessBottleDescPanel.updateExpInfo();
            this._blessBottleDescPanel.updateOnekeyStatus();
            PopupManager.addPopUp(this._blessBottleDescPanel);
            EffectManager.glowFilterUnReg(this._FbExpBottleBtn);
            if (GuideTipsManager.guideTips2.parent == this._FbExpBottleBtn) 
            {
                GuideTipsManager.hideGuideTips2();
            }
            return;
        }

        /* internal  */onGetBottleExp(arg1: DataEvent): void
        {
            GameProxy.friendsProxy.getBlessBottleExp();
            return;
        }

        /* internal  */onGetBottleExpSuccess(arg1: DataEvent): void
        {
            this.hideFbExpBottleButton();
            this._blessBottleDescPanel = null;
            return;
        }

        /* internal  */onShowSendBlessPanel(arg1: DataEvent): void
        {
            if (!this._blessSendPanel) 
            {
                this._blessSendPanel = new FriendBlessSendPanel();
            }
            this._blessSendPanel.updateBlessList();
            this._blessSendPanel.updateBlessNum();
            this._blessSendPanel.show();
            return;
        }

        /* internal  */onFriendBlessSuccess(arg1: SFriendBlessSucess): void
        {
            if (!this._blessReceivePanel || this._blessReceivePanel && this._blessReceivePanel.isHide) 
            {
                if (!this._blessHintIconFu) 
                {
                    this._blessHintIconFu = new BlessHintIconFu();
                }
                this._blessHintIconFu.showIcon([arg1]);
                UiHintIconView.instance.addHintIcon(this._blessHintIconFu);
            }
            else 
            {
                this._blessReceivePanel.showBlessReceive([arg1]);
            }
            return;
        }

        /* internal  */onFriendBlessTipsCommand(arg1: Array<any>): void
        {
            var loc1=null;
            if (cache.role.roleInfo.level < 15) 
            {
                return;
            }
            var loc2=0;
            var loc3=arg1;
            for(loc1 of loc3) 
            {
                cache.friendBless.pushBlessQueue(loc1);
            }
            if (this._blessSendPanel && !this._blessSendPanel.isHide) 
            {
                this._blessSendPanel.updateBlessList();
            }
            else 
            {
                if (!this._blessHintIcon) 
                {
                    this._blessHintIcon = new BlessHintIcon();
                }
                this._blessHintIcon.showIcon(cache.friendBless.blessQueue.length);
                UiHintIconView.instance.addHintIcon(this._blessHintIcon);
            }
            return;
        }

        /* internal  */doSendBless(arg1: DataEvent): void
        {
            var loc1=arg1.data as SFriendBlessInfo;
            if (loc1) 
            {
                cache.friendBless.popBlessQueue(loc1);
                if (ClockManager.instance.nowDate.valueOf() < loc1.timeOutDt.valueOf()) 
                {
                    GameProxy.friendsProxy.bless(loc1.fromPlayerId, loc1.blessLevel, EBlessMsgType._EBlessMsgTypeOne, loc1.blessKey);
                }
                else 
                {
                    MsgManager.showRollTipsMsg(Language.getString(69424));
                }
                if (this._blessSendPanel && !this._blessSendPanel.isHide) 
                {
                    this._blessSendPanel.updateBlessList();
                }
            }
            return;
        }

        /* internal  */onFriendBlessNumChange(arg1): void
        {
            if (this._blessSendPanel && !this._blessSendPanel.isHide) 
            {
                this._blessSendPanel.updateBlessNum();
            }
            return;
        }

        /* internal  */onFriendBlessExpBoottleCommand(arg1: MessageBlock): void
        {
            var loc3=0;
            var loc4=0;
            var loc5=0;
            var loc6=0;
            var loc7=null;
            var loc1=arg1.messageBase as SFriendBlessExpBottle;
            var loc2=cache.friendBless.bottleInfo ? loc1.exp - cache.friendBless.bottleInfo.exp : loc1.exp;
            cache.friendBless.bottleInfo = loc1;
            if (cache.role.roleInfo.level >= cache.friendBless.friendBlessLevel && loc1.exp > 0) 
            {
                if (!this._FbExpBottleBtn || !this._FbExpBottleBtn.parent) 
                {
                    this.showFbExpBottleButton();
                }
                if (this._blessBottleDescPanel && !this._blessBottleDescPanel.isHide) 
                {
                    this._blessBottleDescPanel.updateExpInfo();
                }
                loc3 = RolePlayer.instance.stagePointX;
                loc4 = RolePlayer.instance.stagePointY - 70;
                loc5 = 189;
                loc6 = 199;
                (loc7 = new ExpAddEffect(new ExpAddEffectInfo(loc3, loc4, loc5, loc6, loc2))).playEffect();
            }
            return;
        }

        /* internal  */onRoleLevelUpdate(arg1: PlayerEvent): void
        {
            var loc1=null;
            if (cache.friendBless.bottleInfo && cache.role.roleInfo.level >= cache.friendBless.friendBlessLevel && cache.role.roleInfo.level < 36) 
            {
                this.showFbExpBottleButton();
            }
            if (this._FbExpBottleBtn && cache.friendBless.isOnekeyFriendLevel(cache.role.roleInfo.level) && cache.friendBless.useOneKeyFriendInfo().isCanUse) 
            {
                loc1 = GuideTipsManager.getGuideTips2(GuideTipsManager.Dir_BL, Language.getString(69431));
                loc1.x = 30;
                loc1.y = 0;
                this._FbExpBottleBtn.addChild(loc1);
                EffectManager.glowFilterReg(this._FbExpBottleBtn, [new Object /* flash.filters.GlowFilter */(16776960)]);
            }
            if (this._blessBottleDescPanel && !this._blessBottleDescPanel.isHide) 
            {
                this._blessBottleDescPanel.updateExpInfo();
            }
            return;
        }

        /* internal  */onGetOnekeyFriendsInfo(arg1: Object /* flash.events.Event */=null): void
        {
            GameProxy.friendsProxy.getOneKeyMakeFriendsInfo(this.onGetFriendsInfoSuccess);
            return;
        }

        /* internal  */onGetFriendsInfoSuccess(arg1, arg2: Map<any, any> /* flash.utils.Dictionary */): void
        {
            var loc2=null;
            var loc3=null;
            var loc1=[];
            var loc4=0;
            var loc5=arg2;
            for(loc2 of loc5) 
            {
                (loc3 = new SPublicMiniPlayer()).name = loc2.name;
                loc3.camp = loc2.camp;
                loc3.sex = loc2.sex;
                loc3.entityId = loc2.entityId;
                loc3.career = loc2.career;
                loc3.level = loc2.level;
                loc3.online = 1;
                loc1.push(loc3);
            }
            this.showOneKeyFriendsWin(loc1);
            return;
        }

        /* internal  */onOneKeyMakeFriends(arg1: DataEvent): void
        {
            var loc1=arg1.data as Array<any>;
            GameProxy.friendsProxy.oneKeyMakeFriends(loc1);
            return;
        }

        /* internal  */showOneKeyFriendsWin(arg1: Array<any>): void
        {
            if (!this._oneKeyFriends) 
            {
                this._oneKeyFriends = new OneKeyFriendsWin();
            }
            this._oneKeyFriends.setDataProviderer(arg1);
            this._oneKeyFriends.show();
            return;
        }

        /* internal  */onOneKeyFriendsUseTimeChange(arg1: DataEvent): void
        {
            if (this._blessBottleDescPanel && !this._blessBottleDescPanel.isHide) 
            {
                this._blessBottleDescPanel.updateOnekeyStatus();
            }
            return;
        }

        private /* var */_blessHintIcon: BlessHintIcon;

        private /* var */_blessHintIconFu: BlessHintIconFu;

        private /* var */_blessHintIconFuDic: Map<any, any> /* flash.utils.Dictionary */;

        private /* var */_FbExpBottleBtn: FriendBlessExpBottleButton;

        private /* var */_blessReceivePanel: FriendBlessReceivePanel;

        private /* var */_blessSendPanel: FriendBlessSendPanel;

        private /* var */_blessBottleDescPanel: BlessExpBottleDescPanel;

        private /* var */_oneKeyFriends: OneKeyFriendsWin;
    }
